﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Added
using System.Xml;

namespace GELib
{
   // public LangManager Lang;

    public static class LangManager
    {
        private static List<Phrase> myPhrases;

        public static event EventHandler langLoaded;
        public static void loadLanguage(String filePath)
        {
            if (myPhrases == null)
                myPhrases = new List<Phrase>();

            myPhrases.Clear();

            XmlDocument langFile = new XmlDocument();
            langFile.Load(filePath);
          
            foreach (XmlNode n in langFile.LastChild.ChildNodes)
            {
                Phrase p = new Phrase(n.Name, n.InnerText);
                myPhrases.Add(p);
            }

            if (langLoaded != null)
                langLoaded(null, EventArgs.Empty);
        }

        public static String getPhrase(String index)
        {
            String toReturn = "";

            // Search the corresponding phrase object in myPhrases
            Int32 i = 0;
            Boolean found = false;
            while ((!found) & (i < myPhrases.Count))
            {
                Phrase p = myPhrases[i];
                if(p.index == index)
                {
                    toReturn = p.Text;
                    found = true;
                }
                i++;
            }

            return toReturn;
        }

    }

    public class Phrase
    {
        private String myIndex;
        public String index { get { return myIndex; } }

        private String myText;
        public String Text{get{return myText;}}

        public Phrase(String index, String text)
        {
            myIndex = index;
            myText = text;
        }
    }
}
